#!/bin/bash

# echo -n 参数
# \033[<L>;<C>H"  其中<L>代表此处应该是一个数字，表示坐标行, C为纵坐标, 定位光标
# \033[<N>A"      以当前光标为参照，上移N行, 水平方向不动
# \033[<N>B"      同上，下移
# \033[<N>C"      同上，右移
# \033[<N>D"      同上，左移
# \033[2J"        清屏

# str=""
# while true
# do
#     if [ ${#str} -gt 3 ]
#     then
#         str="."
#         printf "\b\b\b\b "
#     else
#         str="${str}."
#         printf "\r$str"
#         sleep 1
#     fi   
# done



#
#  printf 几个参数
#   \t  水平输出退格键,也就是Tab键
#   \v  垂直输出退格键,也就是Tab键
#   \f  换页
#   \b  输出退格键,也就是Backspace键
#   \c  取消后续输出
#   \a  输出警告声音
#   \n  换行
#   \r  回车
#   \e  向右删除一个字符
#   %ns 输出字符串,n是数字指代输出的几个字符
#   %ni 输出整数,n是数字指代输出几个数字
#   %%  百分号
#
function waiting()
{
    i=0
    while [ $i -le 100 ]
    do
        for j in '\' '|' '/' '-'
        do
            printf "\t\t\t\t%c%c%c%c%c test waiting %c%c%c%c%c\r" "$j" "$j" "$j" "$j" "$j" "$j" "$j" "$j" "$j" "$j"
            sleep 1
        done
        exit
        let i=i+4
    done
}

#waiting

rotate(){
    while true
    do
        for j in '-' '\\' '|' '/'
        do
            echo -ne "\033[1D$j"
            sleep 1
        done
    done
}
#rotate

rotate1(){
    spin='-\|/'

    i=0
    time=0
    while true
    do
        i=$(( (i+1) %4 ))
        printf "\r[ ${spin:$i:1} ] %5ss" $(($time/10))
        s=0.1
        sleep $s
        time=$((time=$time+1))
    done
}
rotate1

progress(){
    i=0
    while [ $i -lt 20 ]
    do
        ((i++))
        echo -ne "=>\033[s"
        echo -ne "\033[40;50H"$((i*5*100/100))%"\033[u\033[1D"
        sleep 1
    done
}

#progress

progress1(){
    while true
    do
        printf "progress [%-50s]%d%% %-10s\r" $j $i "Build nginx"
        sleep .1
        j=">$j"
    done
    echo
}
#progress1


# i=0
# j='#'
# k=('|' '\' '-' '/')
# l=0
# while [ $i -le 25 ]
# do
#     printf "progress:[%-25s][%d%%][%c]\r" $j $(($i*4)) ${k[$l]}
#     j+='#'
#     let i++
#     let l=i%4
#     sleep 0.1
# done
# printf "\n"